from sqlalchemy import Column, INTEGER, VARCHAR, TEXT
from sqlalchemy.ext.declarative import declarative_base

# 创建对象的基类
Base = declarative_base()

# 生成结果历史类
class CalcuResult(Base):
    # 模式名
    __table_args__ = {'schema': 'ESUNTEST'}
    # 表名
    __tablename__ = 'HX_SUM_RESULT'

    ID = Column(VARCHAR(200), primary_key=True)
    GSMC = Column(VARCHAR(200))
    JSONDATA = Column(TEXT)
    TYPE = Column(VARCHAR(200))
    JYND = Column(INTEGER)
    DWBH = Column(VARCHAR(200))

    def __init__(self, ID, GSMC, JSONDATA, TYPE, JYND, DWBH):
        self.ID = ID
        self.GSMC = GSMC
        self.JSONDATA = JSONDATA
        self.TYPE = TYPE
        self.JYND = JYND
        self.DWBH = DWBH

    @classmethod
    def from_dict(cls, data):
        return cls(
            ID=data['ID'],
            GSMC=data['GSMC'],
            JSONDATA=data['JSONDATA'],
            TYPE=data['TYPE'],
            JYND=data['JYND'],
            DWBH=data['DWBH']
        )

    def to_dict(self):
        return {
            'ID': self.ID,
            'GSMC': self.GSMC,
            'JSONDATA': self.JSONDATA,
            'TYPE': self.TYPE,
            'JYND': self.JYND,
            'DWBH': self.DWBH
        }